# -*- coding:utf-8 -*-

## =====================================================================
## Copyright (C) 2007-2011  Jean-Philippe GOLAY
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software
## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
## =====================================================================


from Tkinter import *
import Pmw
import time
from tkMessageBox import *

from Persistance import *
from iCalendar import CalendarGUI
from iNotes import NotesGUI
from iStaff import StaffListGUI
from iProduct import ProductListGUI
from iTime import TimePopupGUI

class CleaningGUI(Toplevel):
	def __init__(self, parent=None, balloon=None, path=None, log=None):
		Toplevel.__init__(self, parent)
		self.parent=parent
		self.grab_set()
		self.transient(self.master)
		self.resizable(width=False, height=False)
		self.title(u"Planning de Ménage de la résidence")
		self.balloon=balloon
		self.imgSearch=PhotoImage(file="img/search_icon.gif")
		self.imgNotes=PhotoImage(file="img/edit.gif")
		self.imgSave=PhotoImage(file="img/save_icon.gif")
		self.imgDelete=PhotoImage(file="img/delete_icon.gif")
		self.imgCalendar=PhotoImage(file="img/calendar.gif")
		self.imgTime=PhotoImage(file="img/time_icon.gif")
		self.hoursListCB = Glob.HOURS_LIST
		self.minutesListCB = Glob.MINUTES_LIST
		self.path=path
		self.log=log
		# Afficher un icon personnalisé
		try:
			if os.name =="posix":
				img = PhotoImage(file=self.path+"/icons/Cleaning-icon.gif")
				self.tk.call("wm", "iconphoto", self._w, img)
			else:
				self.iconbitmap(default=self.path+"/icons/Cleaning-icon.gif")
		except TclError:
			self.log.warning("Le window manager ne supporte pas l'icône que je veux lui mettre...")
		self.log.info("\tCleaningGUI\tStart")
		self.makeCleaning()

	# DEBUT de la gestion du module Cleaning ---------------------------------------------------------------------------------------------------------
	def clearFieldCleaning(self):
		# Mise a zéro des champs
		self.cleaningValues[0].set("")
		self.cleaningValues[1].set("")
		self.cleaningValues[2].set(u"EA")
		self.cleaningValues[3].set("")
		self.cleaningValues[4].set(time.strftime("%d/%m/%Y" ,time.localtime()))
		self.cleaningValues[5].set("")
		self.cleaningValues[6].set("")
		self.cleaningValues[7].set("")
		self.cleaningValues[8].set("")
		self.cleaningValues[9].set("")
		self.cleaningValues[10].set("")
		self.cleaningValues[11].set("")
		self.cleaningValues[12].set("")
		# Remise à zéro des ComboBox
		self.cleaningStatusCB.selectitem(0)
		self.hourRequestCleaningCB.selectitem(0)
		self.minRequestCleaningCB.selectitem(0)
		self.hourFinishCleaningCB.selectitem(0)
		self.minFinishCleaningCB.selectitem(0)
		self.hourCheckedCleaningCB.selectitem(0)
		self.minCheckedCleaningCB.selectitem(0)
		self.cleaningHourRequest=StringVar()
		self.cleaningMinuteRequest=StringVar()
		self.cleaningHourFinish=StringVar()
		self.cleaningMinuteFinish=StringVar()
		self.cleaningHourChecked=StringVar()
		self.cleaningMinuteChecked=StringVar()
		self.listObject=[Product, Stay, Stay, Stay]
		hour = time.strftime("%H" ,time.localtime())
		minute = time.strftime("%M" ,time.localtime())
		# Affichage de l'heure dans la ComboBox 
		count = 0
		for h in self.hoursListCB:
			if h == hour: self.hourRequestCleaningCB.selectitem(count)
			count+=1
		# Affichage des minutes dans la ComboBox
		count = 0
		for m in self.minutesListCB:
			if m == minute: self.minRequestCleaningCB.selectitem(count)
			count+=1
		# Mise à jour des variables heure et minutes
		self.cleaningHourRequest.set(hour)
		self.cleaningMinuteRequest.set( minute)

	def selectCleaning(self, event):
		self.clearFieldCleaning()
		if self.listCleaning.get(0)!="":
			result = Cleaning.select(Cleaning.q.id==self.idListCleaning[int(self.listCleaning.curselection()[0])])
			for row in result:
				self.selectedCleaning = row
			self.listObject[0]=self.selectedCleaning.product
			self.listObject[1]=self.selectedCleaning.requestByClean
			self.listObject[2]=self.selectedCleaning.finishBy
			self.listObject[3]=self.selectedCleaning.checkBy
			if self.selectedCleaning.product != None:self.cleaningValues[0].set(self.listObject[0].number+" - "+self.listObject[0].designation)
			if self.selectedCleaning.requestByClean != None:self.cleaningValues[3].set(self.listObject[1].fname+" - "+self.listObject[1].lname)
			if self.selectedCleaning.finishBy != None:self.cleaningValues[6].set(self.listObject[2].fname+" - "+self.listObject[2].lname)
			if self.selectedCleaning.checkBy != None:self.cleaningValues[9].set(self.listObject[3].fname+" - "+self.listObject[3].lname)
			if self.selectedCleaning.notes != None:self.cleaningValues[12].set(self.selectedCleaning.notes)
			if self.selectedCleaning.designation != None:self.cleaningValues[1].set(self.selectedCleaning.designation)
			if self.selectedCleaning.status != None:self.cleaningValues[2].set(self.selectedCleaning.status)
			# Affichage du status dans la ComboBox
			status = ((u"EA", 0),(u"TR", 1),(u"EC", 2),(u"AV", 3),(u"VU", 4),(u"LI", 5),)
			for n in status:
				if n[0] == self.selectedCleaning.status: self.cleaningStatusCB.selectitem(n[1])
			if self.selectedCleaning.request != None:
				# Affichage de la date de Demande
				self.cleaningValues[4].set(self.selectedCleaning.request.strftime("%d/%m/%Y"))
				# Affichage de l'heure dans la ComboBox 
				count = 0
				for h in self.hoursListCB:
					if h == self.selectedCleaning.request.strftime("%H"): self.hourRequestCleaningCB.selectitem(count)
					count+=1
				# Affichage des minutes dans la ComboBox
				count = 0
				for m in self.minutesListCB:
					if m == self.selectedCleaning.request.strftime("%M"): self.minRequestCleaningCB.selectitem(count)
					count+=1
				# Mise à jour des variables heure et minutes
				self.cleaningHourRequest.set(self.selectedCleaning.request.strftime("%H"))
				self.cleaningMinuteRequest.set(self.selectedCleaning.request.strftime("%M"))
			if self.selectedCleaning.finish != None:
				# Affichage de la date de Effectué
				self.cleaningValues[7].set(self.selectedCleaning.finish.strftime("%d/%m/%Y"))
				# Affichage de l'heure dans la ComboBox 
				count = 0
				for h in self.hoursListCB:
					if h == self.selectedCleaning.finish.strftime("%H"): self.hourFinishCleaningCB.selectitem(count)
					count+=1
				# Affichage des minutes dans la ComboBox
				count = 0
				for m in self.minutesListCB:
					if m == self.selectedCleaning.finish.strftime("%M"): self.minFinishCleaningCB.selectitem(count)
					count+=1
				# Mise à jour des variables heure et minutes
				self.cleaningHourFinish.set(self.selectedCleaning.finish.strftime("%H"))
				self.cleaningMinuteFinish.set(self.selectedCleaning.finish.strftime("%M"))
			if self.selectedCleaning.checked != None:
				# Affichage de la date de Verifié
				self.cleaningValues[10].set(self.selectedCleaning.checked.strftime("%d/%m/%Y"))
				# Affichage de l'heure dans la ComboBox 
				count = 0
				for h in self.hoursListCB:
					if h == self.selectedCleaning.checked.strftime("%H"): self.hourCheckedCleaningCB.selectitem(count)
					count+=1
				# Affichage des minutes dans la ComboBox
				count = 0
				for m in self.minutesListCB:
					if m == self.selectedCleaning.checked.strftime("%M"): self.minCheckedCleaningCB.selectitem(count)
					count+=1
				# Mise à jour des variables heure et minutes
				self.cleaningHourChecked.set(self.selectedCleaning.checked.strftime("%H"))
				self.cleaningMinuteChecked.set(self.selectedCleaning.checked.strftime("%M"))
			# activation du bouton supprimer
			self.deleteCleaningBt.config(state=NORMAL)

	def setCleaning(self, e):
			result = Cleaning.select(Cleaning.q.id==int(e.cleaningID))
			for row in result:
				self.selectedCleaning = row
			self.listObject[0]=self.selectedCleaning.product
			self.listObject[1]=self.selectedCleaning.requestByClean
			self.listObject[2]=self.selectedCleaning.finishBy
			self.listObject[3]=self.selectedCleaning.checkBy
			if self.selectedCleaning.product != None:self.cleaningValues[0].set(self.listObject[0].number+" - "+self.listObject[0].designation)
			if self.selectedCleaning.requestByClean != None:self.cleaningValues[3].set(self.listObject[1].fname+" - "+self.listObject[1].lname)
			if self.selectedCleaning.finishBy != None:self.cleaningValues[6].set(self.listObject[2].fname+" - "+self.listObject[2].lname)
			if self.selectedCleaning.checkBy != None:self.cleaningValues[9].set(self.listObject[3].fname+" - "+self.listObject[3].lname)
			if self.selectedCleaning.notes != None:self.cleaningValues[12].set(self.selectedCleaning.notes)
			if self.selectedCleaning.designation != None:self.cleaningValues[1].set(self.selectedCleaning.designation)
			if self.selectedCleaning.status != None:self.cleaningValues[2].set(self.selectedCleaning.status)
			# Affichage du status dans la ComboBox
			status = ((u"EA", 0),(u"TR", 1),(u"EC", 2),(u"AV", 3),(u"VU", 4),(u"LI", 5),)
			for n in status:
				if n[0] == self.selectedCleaning.status: self.cleaningStatusCB.selectitem(n[1])
			if self.selectedCleaning.request != None:
				# Affichage de la date de Demande
				self.cleaningValues[4].set(self.selectedCleaning.request.strftime("%d/%m/%Y"))
				# Affichage de l'heure dans la ComboBox 
				count = 0
				for h in self.hoursListCB:
					if h == self.selectedCleaning.request.strftime("%H"): self.hourRequestCleaningCB.selectitem(count)
					count+=1
				# Affichage des minutes dans la ComboBox
				count = 0
				for m in self.minutesListCB:
					if m == self.selectedCleaning.request.strftime("%M"): self.minRequestCleaningCB.selectitem(count)
					count+=1
				# Mise à jour des variables heure et minutes
				self.cleaningHourRequest.set(self.selectedCleaning.request.strftime("%H"))
				self.cleaningMinuteRequest.set(self.selectedCleaning.request.strftime("%M"))
			if self.selectedCleaning.finish != None:
				# Affichage de la date de Effectué
				self.cleaningValues[7].set(self.selectedCleaning.finish.strftime("%d/%m/%Y"))
				# Affichage de l'heure dans la ComboBox 
				count = 0
				for h in self.hoursListCB:
					if h == self.selectedCleaning.finish.strftime("%H"): self.hourFinishCleaningCB.selectitem(count)
					count+=1
				# Affichage des minutes dans la ComboBox
				count = 0
				for m in self.minutesListCB:
					if m == self.selectedCleaning.finish.strftime("%M"): self.minFinishCleaningCB.selectitem(count)
					count+=1
				# Mise à jour des variables heure et minutes
				self.cleaningHourFinish.set(self.selectedCleaning.finish.strftime("%H"))
				self.cleaningMinuteFinish.set(self.selectedCleaning.finish.strftime("%M"))
			if self.selectedCleaning.checked != None:
				# Affichage de la date de Verifié
				self.cleaningValues[10].set(self.selectedCleaning.checked.strftime("%d/%m/%Y"))
				# Affichage de l'heure dans la ComboBox 
				count = 0
				for h in self.hoursListCB:
					if h == self.selectedCleaning.checked.strftime("%H"): self.hourCheckedCleaningCB.selectitem(count)
					count+=1
				# Affichage des minutes dans la ComboBox
				count = 0
				for m in self.minutesListCB:
					if m == self.selectedCleaning.checked.strftime("%M"): self.minCheckedCleaningCB.selectitem(count)
					count+=1
				# Mise à jour des variables heure et minutes
				self.cleaningHourChecked.set(self.selectedCleaning.checked.strftime("%H"))
				self.cleaningMinuteChecked.set(self.selectedCleaning.checked.strftime("%M"))
			# activation du bouton supprimer
			self.deleteCleaningBt.config(state=NORMAL)

	def setDateTime(self, e):
		self.cleaningValues[4].set(e.date)
		result=Product.select(Product.q.id==int(e.productID))
		for row in result:
			self.listObject[0]=row
			self.cleaningValues[0].set(self.listObject[0].number+" - "+self.listObject[0].designation)

	def searchCleaning(self, event=None):
		if self.searchCleaningValue.get() != "":
			self.listCleaning.delete(0,END)
			self.idListCleaning = []
			result = Cleaning.select(Cleaning.q.designation.startswith(self.searchCleaningValue.get().encode("utf-8")), orderBy=Cleaning.q.request)
			for row in result:
				self.listCleaning.insert(END, str(row.id)+" - "+row.product.place.company+" - "+row.product.number+" - "+row.product.designation+" - "+row.designation+" - Demande : "+row.request.strftime("%d/%m/%Y %H:%M")+" Etat : "+row.status)
				self.idListCleaning.append(row.id)
		else:
			self.listCleaning.delete(0,END)
			self.idListCleaning = []
			result = Cleaning.select(orderBy=Cleaning.q.request)
			for row in result:
				self.listCleaning.insert(END, str(row.id)+" - "+row.product.place.company+" - "+row.product.number+" - "+row.product.designation+" - "+row.designation+" - Demande : "+row.request.strftime("%d/%m/%Y %H:%M")+" Etat : "+row.status)
				self.idListCleaning.append(row.id)

	def makeCleaning(self):
		leftFrame = Frame(self)
		# Fiche Ménage  (présentation colonne de gauche)
		Label(leftFrame, text=u"Intervention Entretien").pack(side=TOP, fill=X)
		# Création des champs a renseigner pour un object Cleaning
		cleaningStatusListCB = (u"En attente", u"Transmis", u"En cours", u"A vérifié", u"Verifié ok", u"Litige") 
		cleaningLabels = (u"Produit", u"Tâche", u"Avancement", u"Demandé par", u"Demande (date)", u"Demande (heure)", u"Effectué par", u"Effectué (date)", u"Effectué (heure)", u"Vérifié par", u"Vérifié (date)", u"Vérifié (heure)",u"Notes")
		self.cleaningValues = [StringVar(), StringVar(), StringVar(), StringVar(), StringVar(), StringVar(), StringVar(), StringVar(), StringVar(), StringVar(), StringVar(), StringVar(), StringVar()]
		count = 0
		for name in cleaningLabels:
			f = Frame(leftFrame)
			Label(f, width=16, text=name, anchor=W).pack(side=LEFT)
			if count == 0: # Produit (product)
				Entry(f, textvariable=self.cleaningValues[count], width=21, state=DISABLED, bd=0, disabledforeground="black").pack(side=LEFT, fill=X)
				myProduct=Button(f, image=self.imgSearch, command=lambda x=self.cleaningValues[count]:self.ctrlListProduct(x), padx=4, pady=1)
				myProduct.pack(side=RIGHT)
				self.balloon.bind(myProduct, u"Séléctionner un Produit")
			elif count == 2: # Avancement (status -  CB)
				self.cleaningStatusCB=Pmw.ComboBox(f, selectioncommand=self.cleaningStatus, scrolledlist_items=cleaningStatusListCB, listheight=140)
				self.cleaningStatusCB._entryfield._entryFieldEntry.config( width=21)
				self.cleaningStatusCB.pack(side=LEFT, fill=X)
				self.cleaningStatusCB.selectitem(0)
				self.cleaningValues[count].set(u"EA")
			elif count == 3: # Demandé par (Staff - requestByClean)
				Entry(f, textvariable=self.cleaningValues[count], width=21, state=DISABLED, bd=0, disabledforeground="black").pack(side=LEFT, fill=X)
				myRequestBy=Button(f,  image=self.imgSearch, command=lambda x=self.cleaningValues[count]:self.ctrlListStaff(x,1), padx=4, pady=1)
				myRequestBy.pack(side=RIGHT)
				self.balloon.bind(myRequestBy, u"Séléctionner un employé")
			elif count == 4: # Demande date (request)
				Entry(f, textvariable=self.cleaningValues[count], width=21).pack(side=LEFT, fill=X)
				myCal1=Button(f, image=self.imgCalendar, command=lambda x=self.cleaningValues[count]:self.ctrlCalendar(x), padx=4, pady=1)
				myCal1.pack(side=LEFT)
				self.balloon.bind(myCal1, u"Calendrier")
			elif count == 5: # Demande hour (request)
				hStartLb1=Label(f, width=2, text="H", anchor=W)
				hStartLb1.pack(side=LEFT)
				self.balloon.bind(hStartLb1, u"Heure")
				self.hourRequestCleaningCB=Pmw.ComboBox(f, selectioncommand=self.cleaningHourRequest, scrolledlist_items=self.hoursListCB, listheight=100)
				self.hourRequestCleaningCB._entryfield._entryFieldEntry.config( width = 3)
				self.hourRequestCleaningCB.pack(side=LEFT)
				mStartLb1=Label(f, width=3, text="mn", anchor=W)
				mStartLb1.pack(side=LEFT)
				self.balloon.bind(mStartLb1, u"minutes")
				self.minRequestCleaningCB=Pmw.ComboBox(f, selectioncommand=self.cleaningMinuteRequest, scrolledlist_items=self.minutesListCB, listheight=100)
				self.minRequestCleaningCB._entryfield._entryFieldEntry.config( width = 3)
				self.minRequestCleaningCB.pack(side=LEFT)
				# Menu Time
				myTime1=Button(f, image=self.imgTime, padx=1, pady=1)
				myTime1.pack(side=RIGHT)
				myTime1.bind("<ButtonRelease-1>",self.ctrlTimeNow1)
				self.balloon.bind(myTime1, u"Séléctionner une heure")
			elif count == 6: # Effectué par (Staff - finishBy)
				Entry(f, textvariable=self.cleaningValues[count], width=21, state=DISABLED, bd=0, disabledforeground="black").pack(side=LEFT, fill=X)
				myFinishBy=Button(f,  image=self.imgSearch, command=lambda x=self.cleaningValues[count]:self.ctrlListStaff(x,2), padx=4, pady=1)
				myFinishBy.pack(side=RIGHT)
				self.balloon.bind(myFinishBy, u"Séléctionner un employé")
			elif count == 7: # Effectué date (finish)
				Entry(f, textvariable=self.cleaningValues[count], width=21).pack(side=LEFT, fill=X)
				myCal2=Button(f, image=self.imgCalendar, command=lambda x=self.cleaningValues[count]:self.ctrlCalendar(x), padx=4, pady=1)
				myCal2.pack(side=LEFT)
				self.balloon.bind(myCal2, u"Calendrier")
			elif count == 8: # Effectué hour (finish)
				hStartLb2=Label(f, width=2, text="H", anchor=W)
				hStartLb2.pack(side=LEFT)
				self.balloon.bind(hStartLb2, u"Heure")
				self.hourFinishCleaningCB=Pmw.ComboBox(f, selectioncommand=self.cleaningHourFinish, scrolledlist_items=self.hoursListCB, listheight=100)
				self.hourFinishCleaningCB._entryfield._entryFieldEntry.config( width = 3)
				self.hourFinishCleaningCB.pack(side=LEFT)
				mStartLb2=Label(f, width=3, text="mn", anchor=W)
				mStartLb2.pack(side=LEFT)
				self.balloon.bind(mStartLb2, u"minutes")
				self.minFinishCleaningCB=Pmw.ComboBox(f, selectioncommand=self.cleaningMinuteFinish, scrolledlist_items=self.minutesListCB, listheight=100)
				self.minFinishCleaningCB._entryfield._entryFieldEntry.config( width = 3)
				self.minFinishCleaningCB.pack(side=LEFT)
				# Menu Time
				myTime2=Button(f, image=self.imgTime, padx=1, pady=1)
				myTime2.pack(side=RIGHT)
				myTime2.bind("<ButtonRelease-1>",self.ctrlTimeNow2)
				self.balloon.bind(myTime2, u"Séléctionner une heure")
			elif count == 9: # Vérifié par (Staff - checkBy)
				Entry(f, textvariable=self.cleaningValues[count], width=21, state=DISABLED, bd=0, disabledforeground="black").pack(side=LEFT, fill=X)
				myCheckBy=Button(f,  image=self.imgSearch, command=lambda x=self.cleaningValues[count]:self.ctrlListStaff(x,3), padx=4, pady=1)
				myCheckBy.pack(side=RIGHT)
				self.balloon.bind(myCheckBy, u"Séléctionner un employé")
			elif count == 10: # Vérifié date (checked)
				Entry(f, textvariable=self.cleaningValues[count], width=21).pack(side=LEFT, fill=X)
				myCal3=Button(f, image=self.imgCalendar, command=lambda x=self.cleaningValues[count]:self.ctrlCalendar(x), padx=4, pady=1)
				myCal3.pack(side=LEFT)
				self.balloon.bind(myCal3, u"Calendrier")
			elif count == 11: # Vérifié hour (checked)
				hStartLb3=Label(f, width=2, text="H", anchor=W)
				hStartLb3.pack(side=LEFT)
				self.balloon.bind(hStartLb3, u"Heure")
				self.hourCheckedCleaningCB=Pmw.ComboBox(f, selectioncommand=self.cleaningHourChecked, scrolledlist_items=self.hoursListCB, listheight=100)
				self.hourCheckedCleaningCB._entryfield._entryFieldEntry.config( width = 3)
				self.hourCheckedCleaningCB.pack(side=LEFT)
				mStartLb3=Label(f, width=3, text="mn", anchor=W)
				mStartLb3.pack(side=LEFT)
				self.balloon.bind(mStartLb3, u"minutes")
				self.minCheckedCleaningCB=Pmw.ComboBox(f, selectioncommand=self.cleaningMinuteChecked, scrolledlist_items=self.minutesListCB, listheight=100)
				self.minCheckedCleaningCB._entryfield._entryFieldEntry.config( width = 3)
				self.minCheckedCleaningCB.pack(side=LEFT)
				# Menu Time
				myTime3=Button(f, image=self.imgTime, padx=1, pady=1)
				myTime3.pack(side=RIGHT)
				myTime3.bind("<ButtonRelease-1>",self.ctrlTimeNow3)
				self.balloon.bind(myTime3, u"Séléctionner une heure")
			elif count == 12: # Notes
				Entry(f, textvariable=self.cleaningValues[count], width=21).pack(side=LEFT, fill=X)
				myNotes=Button(f, image=self.imgNotes, command=lambda x=self.cleaningValues[count]:self.ctrlNotes(x,u"Notes ménage"), padx=4, pady=1)
				myNotes.pack(side=RIGHT)
				self.balloon.bind(myNotes, u"Détails de la note")
			else: 
				Entry(f, textvariable=self.cleaningValues[count], width=24).pack(side=LEFT, fill=X)
			f.pack(side=TOP, fill=X)
			count += 1
		# Boutons enregistrement (new ou modify) et suppression
		s = Frame(leftFrame) 
		self.saveCleaningBt=Button(s, image=self.imgSave, command=self.createCleaning)
		self.saveCleaningBt.bind("<Return>", self.createCleaning)
		self.saveCleaningBt.pack(side=LEFT)
		self.balloon.bind(self.saveCleaningBt, u"Enregistrer")
		self.deleteCleaningBt=Button(s, image=self.imgDelete, command=self.deleteCleaning, state=DISABLED)
		self.deleteCleaningBt.bind("<Return>", self.deleteCleaning)
		self.deleteCleaningBt.pack(side=LEFT)
		self.balloon.bind(self.deleteCleaningBt, u"Supprimer")
		s.pack(side=TOP, fill=X)
		leftFrame.pack(side=LEFT, fill=X)
		# Liste des Occupation existants (présentation colonne de droite)
		rightFrame = Frame(self) 
		Label(rightFrame, text=u"Liste des Interventions plannifiées").pack(side=TOP, fill=X)
		self.searchCleaningValue = StringVar()
		self.searchCleaningEt = Entry(rightFrame,  width=93, textvariable=self.searchCleaningValue, relief=GROOVE)
		self.searchCleaningEt.bind("<KeyRelease>", self.searchCleaning)
		self.searchCleaningEt.pack(side=TOP, fill=X)
		self.balloon.bind(self.searchCleaningEt, u"Saisir les premières lettres d'un Ménage\npour une recherche plus précise,\nla liste est classée par date de demande.")
		s = Frame(rightFrame) 
		scrollbar = Scrollbar(s)
		scrollbar.pack(side=RIGHT, fill=Y)
		self.listCleaning = Listbox(s)
		self.listCleaning.config(yscrollcommand=scrollbar.set, width=90, selectmode=SINGLE, height=17)
		self.listCleaning.bind("<ButtonRelease-1>",self.selectCleaning)
		scrollbar.config(command=self.listCleaning.yview)
		self.listCleaning.pack()
		self.balloon.bind(self.listCleaning, u"Séléctionner un Ménage\npour la visualiser ou la modifier.")
		s.pack(side=TOP)
		rightFrame.pack(side=RIGHT, fill=BOTH)
		# Initialisation
		self.clearFieldCleaning()
		self.searchCleaning()

	def ctrlTimeNow1(self,event):
		varHour=[self.cleaningHourRequest, self.cleaningMinuteRequest, self.hourRequestCleaningCB, self.minRequestCleaningCB] 
		TimePopupGUI(self, event=event, field=self.cleaningValues[5], varHour=varHour, log=self.log, path=self.path)

	def ctrlTimeNow2(self,event):
		varHour=[self.cleaningHourFinish, self.cleaningMinuteFinish, self.hourFinishCleaningCB, self.minFinishCleaningCB]
		TimePopupGUI(self, event=event, field=self.cleaningValues[8], varHour=varHour, log=self.log, path=self.path)

	def ctrlTimeNow3(self,event):
		varHour=[self.cleaningHourChecked, self.cleaningMinuteChecked, self.hourCheckedCleaningCB, self.minCheckedCleaningCB]
		TimePopupGUI(self, event=event, field=self.cleaningValues[11], varHour=varHour, log=self.log, path=self.path)

	def ctrlCalendar(self,field):
		CalendarGUI(field=field, log=self.log, path=self.path)

	def ctrlNotes(self,field,title):
		NotesGUI(field=field,title=title, log=self.log, path=self.path)

	def ctrlListProduct(self,field):
		ProductListGUI(balloon=self.balloon, field=field, index=0, listObject=self.listObject, log=self.log, path=self.path)

	def ctrlListStaff(self,field,index):
		StaffListGUI(balloon=self.balloon, field=field, index=index, listObject=self.listObject, log=self.log, path=self.path)

	def cleaningStatus(self, value):
		status = ((u"EA", u"En attente"),(u"TR", u"Transmis"),(u"EC", u"En cours"),(u"AV", u"A vérifié"),(u"VU", u"Verifié ok"),(u"LI", u"Litige"),)
		for n in status:
			if n[1] == value: self.cleaningValues[2].set(n[0])

	def cleaningHourRequest(self, value):
		self.cleaningHourRequest.set(value)
		self.minRequestCleaningCB.selectitem(0)
		self.minRequestCleaningCB.invoke()

	def cleaningMinuteRequest(self, value):
		self.cleaningMinuteRequest.set(value)

	def cleaningHourFinish(self, value):
		self.cleaningHourFinish.set(value)
		self.minFinishCleaningCB.selectitem(0)
		self.minFinishCleaningCB.invoke()

	def cleaningMinuteFinish(self, value):
		self.cleaningMinuteFinish.set(value)

	def cleaningHourChecked(self, value):
		self.cleaningHourChecked.set(value)
		self.minCheckedCleaningCB.selectitem(0)
		self.minCheckedCleaningCB.invoke()

	def cleaningMinuteChecked(self, value):
		self.cleaningMinuteChecked.set(value)

	def getDateTimeRequestCleaning(self):
		if self.cleaningValues[4].get() != "":
			date=self.cleaningValues[4].get().split("/")
			d = datetime.datetime(int(date[2]), int(date[1]), int(date[0]), int(self.cleaningHourRequest.get()), int(self.cleaningMinuteRequest.get()), 0)
			return d
		else:
			return None

	def getDateTimeFinishCleaning(self):
		if self.cleaningValues[7].get() != "":
			date=self.cleaningValues[7].get().split("/")
			d = datetime.datetime(int(date[2]), int(date[1]), int(date[0]), int(self.cleaningHourFinish.get()), int(self.cleaningMinuteFinish.get()), 0)
			return d
		else:
			return None

	def getDateTimeCheckedCleaning(self):
		if self.cleaningValues[10].get() != "":
			date=self.cleaningValues[10].get().split("/")
			d = datetime.datetime(int(date[2]), int(date[1]), int(date[0]), int(self.cleaningHourChecked.get()), int(self.cleaningMinuteChecked.get()), 0)
			return d
		else:
			return None

	def verifyCleaning(self):
		if self.cleaningValues[0].get() == "":
			showerror(u"Erreur de saisie", u"Le champ Produit est obligatoire !\nMerci de le compléter.")
			return False
		elif self.cleaningValues[1].get() == "":
			showerror(u"Erreur de saisie", u"Le champ Tâche est obligatoire !\nMerci de le compléter.")
			return False
		elif self.cleaningValues[3].get() == "": 
			showerror(u"Erreur de saisie", u"Le champ Demandé par est obligatoire !\nMerci de le compléter.")
			return False
		elif self.cleaningValues[4].get() == "": 
			showerror(u"Erreur de saisie", u"Le champ Demande Date est obligatoire !\nMerci de le compléter.")
			return False
		elif self.cleaningHourRequest.get() == "" or  self.cleaningMinuteRequest.get() == "": 
			showerror(u"Erreur de saisie", u"Les champs Heures et Minutes de la Demande sont obligatoire !\nMerci de les compléter.")
			return False
		else:
			return True

	def createCleaning(self, event=None):
		if self.verifyCleaning():
			if  self.deleteCleaningBt.config()["state"][4] == "normal":
				self.modifyCleaning()
			else:
				if askyesno(u"Enregistrement", u"Souhaitez-vous enregistrer %s comme un nouveau Ménage ?\n" % self.cleaningValues[1].get()):
					Cleaning(product=self.listObject[0],
						designation=self.cleaningValues[1].get().encode("utf-8"),
						request=self.getDateTimeRequestCleaning(),
						finish=self.getDateTimeFinishCleaning(),
						checked=self.getDateTimeCheckedCleaning(),
						status=self.cleaningValues[2].get().encode("utf-8"),
						requestByClean=self.listObject[1],
						finishBy=self.listObject[2],
						checkBy=self.listObject[3],
						notes=self.cleaningValues[12].get().encode("utf-8"),
						createDate=datetime.datetime.now()
					)
					self.searchCleaning()
				self.clearFieldCleaning()

	def modifyCleaning(self, event=None): 
		if askyesno(u"Modifier", u"Souhaitez-vous modifier la tâche %s ?" % str(self.selectedCleaning.id)):
			self.selectedCleaning.product=self.listObject[0]
			self.selectedCleaning.designation=self.cleaningValues[1].get().encode("utf-8")
			self.selectedCleaning.request=self.getDateTimeRequestCleaning()
			self.selectedCleaning.finish=self.getDateTimeFinishCleaning()
			self.selectedCleaning.checked=self.getDateTimeCheckedCleaning()
			self.selectedCleaning.status=self.cleaningValues[2].get().encode("utf-8")
			self.selectedCleaning.requestByClean=self.listObject[1]
			self.selectedCleaning.finishBy=self.listObject[2]
			self.selectedCleaning.checkBy=self.listObject[3]
			self.selectedCleaning.notes=self.cleaningValues[12].get().encode("utf-8")
			self.searchCleaning()
		self.deleteCleaningBt.config(state=DISABLED)
		self.clearFieldCleaning()

	def deleteCleaning(self, event=None): 
		if askyesno(u"Suppression", u"Souhaitez-vous supprimer le Ménage %s ?\nCette opération est irréversible !" % str(self.selectedCleaning.id)):
			Cleaning.delete(self.selectedCleaning.id)
			self.searchCleaning()            
		self.deleteCleaningBt.config(state=DISABLED)
		self.clearFieldCleaning()
	# FIN de la gestion du module Cleaning ----------------------------------------------------------------------------------------------------------------

#~ class CleaningListGUI(Toplevel):
    #~ def __init__(self, parent=None, balloon=None, field=None, index=None):
        #~ Toplevel.__init__(self, parent)
        #~ self.parent=parent
        #~ self.grab_set() 
        #~ self.transient(self.master)
        #~ self.resizable(width=False, height=False)
        #~ self.title(u"Liste des Articles")
        #~ self.balloon=balloon
        #~ self.field=field
        #~ self.index=index
        #~ self.makeListItem()